﻿namespace ysh.core
{
    using System.Windows.Forms;
    using System.Collections.Generic;
    using Autodesk.Revit.UI;
    using Autodesk.Revit.DB;

    /// <summary>
    /// The wall layer data aquisition form.
    /// </summary>
    public partial class TagWallLayersForm : System.Windows.Forms.Form
    {
        #region private members

        /// <summary>
        /// 
        /// </summary>

        private UIDocument uidoc = null;

        /// <summary>
        /// 
        /// </summary>
        private ElementId textTypeId = null;

        #endregion

        #region constructor

        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="uIDocument"></param>
        public TagWallLayersForm(UIDocument uIDocument)
        {
            InitializeComponent();
            uidoc = uIDocument;
        }

        #endregion

        #region events

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, System.EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            Close();    
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, System.EventArgs e)
        {
            this.DialogResult= DialogResult.Cancel;
            Close();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TagWallLayersForm_Load(object sender, System.EventArgs e)
        {
            PopulateTextNoteTypeList();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmbTextNoteElementType_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            textTypeId = ((KeyValuePair<string, ElementId>)cmbTextNoteElementType.SelectedItem).Value;
        }
        #endregion

        #region public methods

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public TagWallLayersCommandData GetInformation()
        {
            //information grather from window.
            var information = new TagWallLayersCommandData()
            {
                Function = chkFunction.Checked,
                Name = chkName.Checked,
                Thickness = chkThickness.Checked,
                TextTypeId = textTypeId
            };

            return information; 
        }

        #endregion

        #region private methods

        private void PopulateTextNoteTypeList()
        {
            var doc = uidoc.Document;

            var allTextNoteElementTypes = new FilteredElementCollector(doc).OfClass(typeof(TextElementType));

            var list = new List<KeyValuePair<string,ElementId>>();

            foreach (var item in allTextNoteElementTypes)
                list.Add(new KeyValuePair<string, ElementId>(item.Name, item.Id));

            cmbTextNoteElementType.DataSource = null;
            cmbTextNoteElementType.DataSource = new BindingSource(list,null);
            cmbTextNoteElementType.DisplayMember = "Key";
            cmbTextNoteElementType.ValueMember = "Value";
        }
		#endregion

	}
}
